
 /**
 * HibernateUserInfoDao.java.java.
 * User: BrianChen Date: 2012-6-5 下午04:20:08
 *
 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
 * All rights reserved.
 */
package com.collapsar.core.security.dao.impl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.collapsar.core.orm.hibernate.BaseHibernateDao;
import com.collapsar.core.security.dao.IUserInfoDao;
import com.collapsar.core.security.model.UserInfo;

/**
 * <pre>
 * REVISIONS: 
 * Version 	Date 		Author 			Description
 * ------------------------------------------------------------------- 
 * 1.0 		2012-6-5 	BrianChen 	1. Created this class. 
 * </pre>
 * 
 * @author BrianChen
 * @date 2012-6-5 下午04:20:08
 * @version 1.0
 * @see
 * 
 */
public class HibernateUserInfoDao extends BaseHibernateDao implements IUserInfoDao{

	@Override
	public UserInfo getById(Long userInfoId) {
		return (UserInfo)this.get(UserInfo.class, userInfoId);
	}
	
	@Override
	public void storeUserInfo(UserInfo userInfo) {
		this.store(userInfo);
	}

	@Override
	public void deleteAllUserInfo(Long[] userInfoIds) {
		this.deleteAll(UserInfo.class, userInfoIds);
	}

	@Override
	public void deleteUserInfo(UserInfo userInfo) {
		this.delete(userInfo);
	}

	@Override
	public UserInfo loadUserInfo(Long userInfoId) {
		return (UserInfo)this.load(UserInfo.class, userInfoId);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public UserInfo getUserInfoByUserAccount(final String userAccount) {
		UserInfo userInfo = (UserInfo)this.getHibernateTemplate().execute(
				new HibernateCallback(){
					@Override
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						return session.getNamedQuery("GetUserInfoByUserAccount")
							.setParameter("userAccount", userAccount)
							.uniqueResult();
					}}
				);
		return userInfo;
	}


}

